//
//  BNHomeDetailTableViewCell.m
//  BNCodeGuide
//
//  Created by Mac on 2021/5/22.
//  Copyright © 2021 kevin007. All rights reserved.
//

#import "BNHomeDetailTableViewCell.h"

@interface BNHomeDetailTableViewCell ()
/** titleLabel*/
@property (nonatomic, strong) UILabel *titleLabel;
/** bottom line*/
@property (nonatomic, strong) UIView *bottomLineView;
@end
@implementation BNHomeDetailTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    
    return self;
}

#pragma mark - ----------------SetupUI----------------
- (void)setupUI {
    [@[self.titleLabel,
       self.bottomLineView] enumerateObjectsUsingBlock:^(UIView *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self.contentView addSubview:obj];
    }];
    
    [self addLayouts];
}

#pragma mark - ----------------AddLayouts----------------
- (void)addLayouts {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.centerY.mas_offset(0);
        make.top.mas_offset(20);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.bottom.right.mas_offset(0);
        make.height.mas_equalTo(.5);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setFrame:(CGRect)frame {
    CGRect rect = frame;
    rect.origin.x += 15;
    rect.size.width -= rect.origin.x * 2;
    
    super.frame = rect;
}

- (CGRect)frame {
    return [super frame];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (self.isLastCell) {
        [self setCornerRadiusWithRadius:10 corner:UIRectCornerBottomRight|UIRectCornerBottomLeft];
    }else {
        self.layer.mask = nil;
    }

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - ----------------Getter & Setter----------------
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _titleLabel.textColor = [UIColor randomColor];
        _titleLabel.font = [UIFont lx_PingFangSRegular:18];
    }
    
    return _titleLabel;
}

- (UIView *)bottomLineView {
    if (!_bottomLineView) {
        _bottomLineView = [UIView new];
        _bottomLineView.backgroundColor = [UIColor lightGrayColor];
    }
    
    return _bottomLineView;
}

- (void)setText:(NSString *)text {
    _text = text;
    
    self.textLabel.text = text;
}

@end
